package com.example.hash;


import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.Map;

@RestController
@CrossOrigin(origins = "http://localhost:8081")
@RequestMapping("/GetHash")
public class getTextHashController {
    private final GetTextMapper getTextMapper;
    String outputPath ="D:\\javaproject\\hash\\src\\main\\resources\\file\\memoryHash";


    @Autowired
    public getTextHashController(GetTextMapper getTextMapper) {
        this.getTextMapper = getTextMapper;
    }

    @GetMapping("/GetOnly")
    public String GetOnlyHash(String filePath) {
        try {
            String hash = getTextMapper.onlyText(filePath);
            return ("文件哈希值: " + hash);
        } catch (Exception e) {
            return ("计算哈希失败: " + e.getMessage());
        }
    }

    /*@GetMapping("/GetAll")
    public String GetAllHash(String dirPath) {
        try {
            System.out.println("开始计算目录下所有文件哈希...");
            Map<String, String> hashes = getTextMapper.allText(dirPath);

            hashes.forEach((file, hash) ->
                    System.out.printf("文件: %s\n哈希值: %s\n\n", file, hash));


        } catch (Exception e) {
            return ("错误: " + e.getMessage());
            e.printStackTrace();
        }
    }*/






}
